package loggeri.android.namespace;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View.OnClickListener;
import android.widget.ScrollView;
import android.widget.LinearLayout;
import android.widget.Button;
import android.widget.TextView;
import android.widget.EditText;
import android.widget.CheckBox;



public class TietokantaLoggeriActivity extends Activity  {
    /** Called when the activity is first created. */
	ChainHandler handleri;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
        
        View v = new View(this);
        handleri = new ChainHandler(v);
        v.rekChainHandler(handleri);
        
        //Komentti
        
        handleri.luoPaiva(this);
        handleri.luoKetju(this, "Juoksu");
        handleri.luoKetju(this,"Koodaus");
        handleri.luoKetju(this,"Soutu");
        handleri.luoPaiva(this);
        handleri.luoPaiva(this);
        handleri.luoPaiva(this);
        handleri.luoPaiva(this);
        handleri.luoPaiva(this);
        handleri.luoKetju(this,"Muff");
        handleri.luoPaiva(this);
        handleri.luoPaiva(this);
        handleri.luoPaiva(this);
        handleri.luoPaiva(this);
        handleri.luoPaiva(this);
        handleri.luoPaiva(this);
        handleri.luoPaiva(this);
        handleri.luoPaiva(this);
        handleri.luoPaiva(this);
        handleri.luoPaiva(this);
        handleri.luoPaiva(this);
        
        
           
        this.setContentView(handleri.getView().getSv());
        
        
    }
    
    
    
    @Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
    	super.onDestroy();
		handleri.Nollaa();
	}
    
    



	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub
		super.onBackPressed();
		handleri.Nollaa();
	}



	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		handleri.Nollaa();
	}



	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.layout.menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle item selection
        switch (item.getItemId()) {
            case R.id.lisaa_laji:
            	AlertDialog alertDialog = new AlertDialog.Builder(TietokantaLoggeriActivity.this).create();
        		alertDialog.setTitle("Ketjun nimi");
        		//alertDialog.setMessage("Anna osoite johon navigoidaan");
        		final EditText osote = new EditText(this);
        		osote.setText("");
        		alertDialog.setView(osote);
        		
        		alertDialog.setButton2("Luo", new DialogInterface.OnClickListener() {
        		      public void onClick(DialogInterface dialog, int which) {
        		 
        		    	  String urli = osote.getText().toString().trim();
        		    	
        		    	  handleri.luoKetju(TietokantaLoggeriActivity.this,urli);
        		    		
        		    		 
        		 
        		    } }); 
        		alertDialog.show();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
		
		
	}